package com.example.demo4.service;

import com.example.demo4.domain.Student;


import com.example.demo4.repository.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
<<<<<<< HEAD
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
=======
>>>>>>> bcb091a17987267f0d65e4154f997543fe5bec34
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
<<<<<<< HEAD
public interface StudentService {
    // 通过学生姓名查询
    List<Student> findByNameLike(String name) ;
    // 查询全部
    List<Student> findAll() ;
    // 插入
    Student insert(Student student) ;
    // 更改
    void update(Student student) ;
    // 通过id删除
    void deleteById(Integer id) ;
    // 通过id查询
    Student findById(Integer id) ;
    // 只支持分页的查询
    Page<Student> findAll(Pageable pageable);
=======
public class StudentService {
    @Autowired

    // Service 需要引用 Repository 中的方法
    private StudentRepository studentRepository;
    //按名字查询
    public List<Student> findByNameLike(String name) {

        List <Student> students = studentRepository.findByNameLike(name);
        return students;
    }


    // 查询全部
    public List<Student> findAll() {
        //  StudentRepository 里面自带findAll()
        return studentRepository.findAll();
    }
    //插入
    public Student insert(Student student) {
        return 	studentRepository.save(student);
    }


    // 更改
    public void update(Student student) {

        studentRepository.save(student);
    }
    // 删除
    public void deleteById(Integer id) {
        System.out.println("step2");
        studentRepository.deleteById(id);
    }

    public Student findById(Integer id) {
        return studentRepository.findById(id).orElse(null);
    }
>>>>>>> bcb091a17987267f0d65e4154f997543fe5bec34
}
